#include "stdio.h"
#include "string.h"


int gettot2(int shu)
{
	int tot;
	tot=0;
	while (shu>0)
	{
		tot+=shu%12;
		shu/=12;
	}
	return tot;
}

int gettot3(int shu)
{
	int tot=0;
	while (shu>0)
	{
		tot+=shu%16;
		shu/=16;
	}	
	return tot;
}



main()
{
	int a,b,c,d,shu;
	int tot1,tot2,tot3;

//	printf("%d",gettot2(2992));
	
	for (a=1;a<=9;a++)
		for (b=0;b<=9;b++)
			for (c=0;c<=9;c++)
				for (d=0;d<=9;d++)
				{
					tot1=a+b+c+d;
					shu=1000*a+100*b+10*c+d;
					tot2=gettot2(shu);
					if (tot1!=tot2) continue;
					tot3=gettot3(shu);
					if (tot1==tot2&&tot1==tot3)
					{
						printf("%d\n",shu);
					}
					
				}
	return 0;
}